﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PingPong 
{
    class Ball
    {

        public Texture2D ballTexture;
        public Vector2 ballPosition;
        public Rectangle ballRectangle;
        int screenHeight;
        int screenWidth;
        
        public int ballTextureWidth;
        public int ballTextureHeight;

        public int ballSpeedX = 4;
        public int ballSpeedY = 4;
        
        
  
        public Ball(Texture2D newTexture, Vector2 newBallPosition, int newTextureHeight, int newTextureWidth, int newScreenHeight, int newScreenWidth)
        {
            ballTexture = newTexture;
            ballPosition = newBallPosition;
            ballTextureHeight = newTextureHeight;
            ballTextureWidth = newTextureWidth;
            
            screenHeight = newScreenHeight;
            screenWidth = newScreenWidth;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(ballTexture, ballPosition, Color.White);
        }

        public void Update()
        {
            ballRectangle = new Rectangle((int)ballPosition.X, (int)ballPosition.Y, ballTextureWidth, ballTextureHeight);
            ballPosition.X += ballSpeedX;
            ballPosition.Y -= ballSpeedY;

            if (ballPosition.X<= 0)
                ballSpeedX = -ballSpeedX;


            if (ballPosition.X + ballTextureWidth >= screenWidth)
                ballSpeedX = -ballSpeedX;


            if (ballPosition.Y <= 0)
                ballSpeedY = -ballSpeedY;


            if (ballPosition.Y + ballTextureHeight >= screenHeight)
                ballSpeedY = -ballSpeedY;

        }
    }
}
